package cn.aib.eduservice.controller.front;

import cn.aib.commonutils.R;
import cn.aib.eduservice.entity.EduCourse;
import cn.aib.eduservice.entity.EduTeacher;
import cn.aib.eduservice.service.EduCourseService;
import cn.aib.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacherfront")
//@CrossOrigin
public class EduTeacherFrontController {

    @Autowired
    private EduTeacherService eduTeacherService;
    @Autowired
    private EduCourseService eduCourseService;

    /**
     *  前台查询讲师列表
     *  方法名：getTeacherFrontList
     *  参数：long current,long limit
     *  返回值：R
     */

    @GetMapping("getTeacherFrontList/{current}/{limit}")
    public R getTeacherFrontList(@PathVariable long current, @PathVariable long limit){

        //调用eduTeacherService查询讲师分页数据，返回map，map封账了分页数据
        Map<String,Object> pageTeacher = eduTeacherService.selectTeacherFrontList(current,limit);

        return R.ok().data(pageTeacher);
    }

    /**
     *  查询讲师信息和课程信息
     *  方法名：getTeacherInfoAndCourseInfo
     *  参数：String id (讲师的id)
     *  返回值：R
     */

    @GetMapping("getTeacherInfoAndCourseInfo/{id}")
    public R getTeacherInfoAndCourseInfo(@PathVariable String id){
        //查收讲师信息
        EduTeacher teacher = eduTeacherService.getById(id);

        //查询课程信息
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();

        wrapper.eq("teacher_id",id);

        List<EduCourse> eduCourseList = eduCourseService.list(wrapper);

        //返回
        return R.ok().data("teacher",teacher).data("courseList",eduCourseList);
    }
}
